package com.ocean.recommendationserver.realtimerecommend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ocean.recommendationserver.realtimerecommend.constant.PageConstant;
import com.ocean.recommendationserver.realtimerecommend.entity.Movie;
import com.ocean.recommendationserver.realtimerecommend.mapper.MovieMapper;
import com.ocean.recommendationserver.realtimerecommend.service.IMovieService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocean.recommendationserver.realtimerecommend.util.PageUtils;
import com.ocean.recommendationserver.realtimerecommend.util.Query;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ocean
 * @since 2021-07-18
 */
@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie> implements IMovieService {

    @Override
    public PageUtils getMoviesByPage(Integer page, Integer limit) {
        Map<String, Object> pageParam = new HashMap<>();
        pageParam.put(PageConstant.PAGE, page);
        pageParam.put(PageConstant.LIMIT, limit);

        QueryWrapper<Movie> movieQueryWrapper = new QueryWrapper<>();
        IPage<Movie> movieIPage = this.page(new Query<Movie>().getPage(pageParam, "mid", true)
                , movieQueryWrapper);
        return new PageUtils(movieIPage);
    }
}
